package com.semis.business.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import com.semis.common.utils.StringUtils;

import java.util.List;
import java.util.Map;

import com.semis.business.system.mapper.SysFilesMapper;
import com.semis.business.system.domain.SysFiles;
import com.semis.business.system.service.ISysFilesService;

/**
 * 系统附件Service业务层处理
 *
 * @author cyxh
 * @date 2024-06-11
 */
@Service
public class SysFilesServiceImpl extends ServiceImpl<SysFilesMapper, SysFiles> implements ISysFilesService {

    @Autowired
    private SysFilesMapper sysFilesMapper;

    /**
     * 查询系统附件列表
     *
     * @param sysFiles 系统附件
     * @return 系统附件
     */
    @Override
    public List<SysFiles> selectSysFilesList(SysFiles sysFiles)
    {
        List<SysFiles> sysFilesList = sysFilesMapper.selectList(buildQueryWrapper(sysFiles));
        return sysFilesList;
    }

    private LambdaQueryWrapper<SysFiles> buildQueryWrapper(SysFiles query) {
        Map<String, Object> params = query.getParams();
        LambdaQueryWrapper<SysFiles> lqw = Wrappers.lambdaQuery();
        lqw.like(StringUtils.isNotBlank(query.getOriginName()), SysFiles::getOriginName, query.getOriginName());
        lqw.eq(StringUtils.isNotBlank(query.getLocation()), SysFiles::getLocation, query.getLocation());
        lqw.eq(StringUtils.isNotBlank(query.getFileType()), SysFiles::getFileType, query.getFileType());
        lqw.eq(query.getFileSize() != null, SysFiles::getFileSize, query.getFileSize());
        lqw.eq(StringUtils.isNotBlank(query.getAddition()), SysFiles::getAddition, query.getAddition());
        lqw.orderByDesc(SysFiles::getCreateTime);
        return lqw;
    }
}
